//
//  NewFunctToViewController.swift
//  yimiao
//
//  Created by Qingke on 16/3/31.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class NewFunctToViewController: UIViewController {

    @IBOutlet weak var button: UIButton!
    
    var time = NSTimer()
    var totalTime :Double = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        button.addTarget(self, action: "startRun", forControlEvents: .TouchDown)
        button.addTarget(self, action: "stopRun", forControlEvents: .TouchUpInside)
        
        
        time.invalidate()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
   
    
    @IBAction func backButton(sender: UIButton) {
        self.dismissViewControllerAnimated(true, completion: nil)
        
        print(String(format: "结束了一共用了%f", arguments: [totalTime]))
        time.invalidate()
    }
    
    func tickDown() {
        print("tick")
        totalTime += 0.1
        
    }
    
    func startRun () {
        time = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "tickDown", userInfo: nil, repeats: true)
        print("开始了")
    }
    
    func stopRun(){
        time.invalidate()
        print("结束了")
    }
}
